<?php

/**
 * Request封装
 *
 * Author: Surfin
 * Datetime: 16/10/20 下午2:21
 */

namespace Utils;

use Symfony\Component\HttpFoundation\Request;

class Requests
{

    private $request;

    private $get;

    private $post;

    private $attributes;

    public function __construct(Request $request)
    {
        $this->request = $request;

        $this->get = $request->query;
        $this->attributes = $request->attributes;
        $this->post = $request->request;
    }

    public function get($key, $default = null)
    {
        $value = $this->request->get($key, $default);

        return empty($value) ? $default : $value;
    }

    public function getGet($key, $default = null)
    {
        $value = $this->get->get($key, $default);

        return empty($value) ? $default : $value;
    }

    public function getPost($key, $default = null)
    {
        $value = $this->get->get($key, $default);

        return empty($value) ? $default : $value;
    }

    public function getPostAll()
    {
        return $this->post->all();
    }

    public function getGetAll()
    {
        return $this->get->all();
    }


    public function set($key, $value, $request = 'query')
    {
        $this->request->{$request}->set($key, $value);
    }

    public function setGet($key, $value)
    {
        $this->set($key, $value, 'query');
    }

    public function setPost($key, $value)
    {
        $this->set($key, $value, 'request');
    }

}
